package com.ws.common.util;

import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.serializer.SerializerFeature;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;

/**
 * Created by WS on 2018/1/26.
 */
public class ResponseResult implements Serializable {
    private String code;
    private String msg;
    private Object data;


    public ResponseResult() {
        this(ResultCode.Common.SUCCESS,"");
    }

    public ResponseResult(Object data) {
        this(ResultCode.Common.SUCCESS,data);
    }


    public ResponseResult(ResultCode returnMsg){
        this(returnMsg,"");
    }


    public ResponseResult(ResultCode returnMsg, Object data){
        this.code=returnMsg.getCode();
        this.msg=returnMsg.getMsg();
        this.data=data;
    }

    public ResponseResult(String code, String  msg){
        this.code=code;
        this.msg=msg;
        this.data="";
    }
    public ResponseResult(String code, String  msg,Object data){
        this.code=code;
        this.msg=msg;
        this.data=data;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }

    @Override
    public String toString() {
        Map< String , Object > jsonMap = new HashMap<>();
        jsonMap.put("code",this.code);
        jsonMap.put("msg",this.msg);
        jsonMap.put("data",this.data);
        return JSONObject.toJSONString(jsonMap, SerializerFeature.WriteNullStringAsEmpty,SerializerFeature.WriteDateUseDateFormat);
    }
}
